package com.jxdinfo.hussar.example.common.schedulingtask.scheduleutil;

import com.jxdinfo.hussar.example.common.schedulingtask.model.MdItemType;
import com.jxdinfo.hussar.example.common.schedulingtask.model.SysOrganMes;
import com.jxdinfo.hussar.example.common.schedulingtask.model.SysStruMes;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author QiaoBin
 * @Date 2024/4/10 11:52
 * @PackageName com.jxdinfo.hussar.example.common.schedulingtask.scheduleutil
 * @ClassName ScheduleUtils
 * @Description: 定时任务的相关工具类
 * @Version 1.0
 */
public class ScheduleUtils {

    /**
     * @Author QiaoBin
     * @Date 2024/4/10 11:52
     * @param mdItemTypeList 对象列表集合
	 * @param childId id
     * @Description 获取当前数据的所有的parentTypeid
     */
    public static List<Long> getAllParentIds(List<MdItemType> mdItemTypeList, Long childId) {
        List<Long> parentIds = new ArrayList<>();
        for (MdItemType obj : mdItemTypeList) {
            if (obj.getItemTypeId() == childId) {
                parentIds.add(obj.getParentTypeId());
                if (obj.getParentTypeId() != null || "".equals(obj.getParentTypeId())) {
                    parentIds.addAll(getAllParentIds(mdItemTypeList, obj.getParentTypeId()));
                }
                break;
            }
        }
        return parentIds;
    }

    public static List<Long> getAllParentIdsSysStru(List<SysStruMes> mdItemTypeList, Long childId) {
        List<Long> parentIds = new ArrayList<>();
        for (SysStruMes obj : mdItemTypeList) {
            if (obj.getSTRU_ID().equals(childId)) {
                parentIds.add(obj.getPARENT_ID());
                if (obj.getPARENT_ID() != null || obj.getPARENT_ID().equals("")) {
                    parentIds.addAll(getAllParentIdsSysStru(mdItemTypeList, obj.getPARENT_ID()));
                }
                break;
            }
        }
        return parentIds;
    }

    public static List<String> getAllParentIdsSysOrganFcode(List<SysStruMes> mdItemTypeList, Long childId) {
        List<String> parentIds = new ArrayList<>();
        for (SysStruMes obj : mdItemTypeList) {
            if (obj.getSTRU_ID().equals(childId)) {
                parentIds.add(obj.getORGAN_CODE());
                if (obj.getORGAN_CODE() != null || obj.getORGAN_CODE().equals("")) {
                    parentIds.addAll(getAllParentIdsSysOrganFcode(mdItemTypeList, obj.getPARENT_ID()));
                }
                break;
            }
        }
        return parentIds;
    }

    public static List<String> getAllParentIdsSysOrganFname(List<SysStruMes> mdItemTypeList, Long childId) {
        List<String> parentIds = new ArrayList<>();
        for (SysStruMes obj : mdItemTypeList) {
            if (obj.getSTRU_ID().equals(childId)) {
                parentIds.add(obj.getORGAN_ALIAS());
                if (obj.getORGAN_CODE() != null || obj.getORGAN_CODE().equals("")) {
                    parentIds.addAll(getAllParentIdsSysOrganFcode(mdItemTypeList, obj.getPARENT_ID()));
                }
                break;
            }
        }
        return parentIds;
    }
}
